package com.example.mapper;

import com.example.common.BaseResponse;
import com.example.model.user.EditPersonalInfo;
import com.example.model.user.User;
import com.example.model.user.UserUpdateRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    //根据用户名和密码查询用户
    @Select("select * from users where username=#{userName} and user_password=#{newPassword}")
    User getByNameAndPassword(String userName, String newPassword);

    //根据用户名查询
    @Select("select username from users where username=#{username}")
    String getByUsername(String userName);

    //插入新用户
    @Insert("insert into users (username,user_password)values (#{username},#{userPassword})")
    void save(User user);

    //根据id查询用户
    @Select("select * from users where id=#{id}")
    User getById(Long id);

    @Select("select * from users")
    List<User> getUserList();

    /**
     * 用户名模糊查询
     * @return 用户名集合
     */
    @Select("select * from users where username like #{username}")
    List<User> getUserByName(String userName);

    /**
     * 更新用户
     * @param userUpdateRequest 更新用户实体
     * @return 是否更新成功
     */
    Boolean updateUser(UserUpdateRequest userUpdateRequest);

    /**
     * 根据id删除用户
     * @param id 用户id
     * @return 是否删除成功
     */
    @Delete("delete from users where id=#{id}")
    Boolean deleteUser(Long id);

    /**
     * 编辑个人信息
     * @param personalInfo 个人信息
     * @return 是否成功
     */
    Boolean updateInfo(EditPersonalInfo personalInfo);

    /**
     * 修改密码
     * @return 是否修改成功
     */
    @Update("update hotelbook.users set hotelbook.users.user_password =#{newPassword} where hotelbook.users.id=#{id}")
    Boolean updatePassword(Long id, String newPassword);

    /**
     * 重置密码
     * @param id 用户id
     * @param newPassword 加密密码
     * @return 是否成功
     */
    @Update("update hotelbook.users set hotelbook.users.user_password=#{newPassword} where hotelbook.users.id=#{id}")
    Boolean resetPassword(Long id, String newPassword);
}
